# -*- coding:utf-8 -*-
# @FileName  :t1t18t24.py
# @Time      :2021/5/19 15:55
import io
import json
import sys
import time
from time import sleep
from lxml import html
import aiohttp, asyncio
# import uvloop
from fake_useragent import UserAgent

# asyncio.set_event_loop_policy()
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')
sys.setrecursionlimit(1000000)
ua = UserAgent()
etree = html.etree
headers = {
    # 'Content-Type': 'application/json;charset=UTF-8',
    # 'Host': 'holmes.taobao.com',
    # 'Accept-Encoding': 'gzip',
    'User-agent': ua.random,
    # 'Connection': 'close',
    # 'X-XSRF-TOKEN': '44990af6-5c83-4752-a714-cf438ae6be3f',
    # 'deviceId': '8f6e3733ca6af1d918de5b31f7cb12',
    # 'authcode': '0ab3f07ca4e03f53bd760e31510532ba',
    # "connection":"close"
}

tt = time.strftime('%Y-%m-%d %H:%M:%S')

k = {}


async def one():
    data = {
        "region": {"area": '通州区'},
        "hasConcatWay": ["有联系电话"],
        "bizCategory": {"bizCategory": "批发和零售业"},
        "companyType": ["有限责任公司"],
        "keyword": '服装',
        "pageNo": 1, "pageSize": 50,
        "orderByType": 5, "deviceId": '', "authCode": '', "platform": "tb",
    }
    # async with aiohttp.ClientRequest() as session:
    async with aiohttp.request('GET', url='https://i.meituan.com/index/changecity?cevent=imt%2Fhd%2FcityBottom', headers=headers) as r:
        w = await r.text()
        w1 = etree.HTML(w)
        a = w1.xpath("//ul[@class='table']/li/a/@href")
        c = w1.xpath("//ul[@class='table']/li/a/text()")
        for i, j in zip(a, c):
            if j in b1:
                k[j] = i.replace('//i.meituan.com/', '')[:-1]


# async def two(w):
#     url = 'https://holmes.taobao.com/ding/corpquery/company/category2V3'
#     data = {
#         "companyName": w,
#         "deviceId": "a9eae24bba847a2616c9a87862df96bb",
#         "authCode": '',
#         "platform": "tb"}
#     async with aiohttp.request('POST',url=url,  data=json.dumps(data), headers=headers) as r:
#         b = await r.json()
#         print(b['data']['summary']['companyName'])
#     # input('')
b = ['山西:长治:0131', '辽宁:朝阳:0160', '安徽:六安:0203', '河南:漯河:0242', '贵州:铜仁:0325', '贵州:毕节:0327', '河南:巩义:0553', '山东:蓬莱:0587', '山东:乐陵:0611', '安徽:天长:0626',
     '河南:长葛:0627', '湖北:宜都:0656', '台湾:恒春:0712', '台湾:嘉义市:0719', '重庆:北碚:0731', '湖南:邵东:0736', '河北:乐亭:0744', '河北:滦县:0745', '河南:淮阳:0758', '安徽:芜湖县:0773',
     '安徽:繁昌:0774', '安徽:广德:0780', '河南:鲁山:0786', '山西:太谷:0790', '河南:长垣:0795', '山西:怀仁:0806', '河南:中牟:0821', '山东:单县:0830', '甘肃:华亭:0856', '河南:浚县:0863',
     '山西:洪洞:0867', '山东:茌平:0877', '陕西:彬县:0915', '湖北:京山:0918', '广东:佛冈:0921', '四川:什邡:0953', '江西:于都:0958', '吉林:珲春:0977', '广西:平果:0991', '四川:射洪:0992',
     '安徽:潜山:1004', '河北:任县:1012', '河北:南和:1013', '贵州:赤水:1018', '河北:泊头市:1074', '河南:洛宁:1087', '湖南:茶陵:1097', '安徽:长丰县:1100', '河南:宁陵:1112', '陕西:南郑区:1125',
     '重庆:酉阳土家族苗族自治县:1127', '重庆:秀山土家族苗族自治县:1129', '山东:长清区:1157', '黑龙江:嫩江县:1166', '四川:新津县:1167', '广西:靖西市:1197', '云南:澄江县:1205', '重庆:丰都:1231',
     '重庆:彭水苗族土家族自治县:1232', '河北:大厂回族自治县:1233', '湖北:大悟县:1243', '云南:景谷:1252', '云南:富民:1253', '云南:禄劝彝族苗族自治县:1254', '云南:石林彝族自治县:1272']
b1 = []
for i in b:
    b1.append(i.split(':')[1])
for i in b1:
    k[i] = ''
loop = asyncio.get_event_loop()
loop.run_until_complete(one())

# print(k.keys())
# asyncio.run(one())
# print(time.strftime('%Y-%m-%d %H:%M:%S'))

# print(len(b))

sd = {'长治': 'changzhi', '朝阳': 'chaoyang', '六安': 'liuan', '漯河': 'luohe', '铜仁': 'tongrendiqu', '毕节': 'bijiediqu', '巩义': 'gongyishi', '蓬莱': 'penglaiqu',
      '乐陵': 'laoling',
      '天长': 'tianchang', '长葛': 'changge', '宜都': 'yidu', '恒春': 'hengchun', '嘉义市': 'jiayi', '北碚': 'beipei', '邵东': 'shaodongshi', '乐亭': 'laoting',
      '滦县': 'luanzhoushi', '淮阳': 'huaiyangqu',
      '芜湖县': 'wuhu', '繁昌': 'fanchangqu', '广德': 'guangdeshi', '鲁山': 'lushanls', '太谷': 'taiguqu', '长垣': 'changyuanshi', '怀仁': 'huairenxian', '中牟': 'zhongmou',
      '单县': 'shanxian', '华亭': 'huatingshi', '浚县': 'xunxian',
      '洪洞': 'hongtong', '茌平': 'chipingqu', '彬县': 'binzhoushi', '京山': 'jingshanshi', '佛冈': 'fogang', '什邡': 'shifang', '于都': 'yudu', '珲春': 'hunchun', '平果': 'pingguoshi',
      '射洪': 'shehongshi', '潜山': 'qianshanshi', '任县': 'renzequ',
      '南和': 'nanhequ', '赤水': 'chishui', '泊头市': 'botou', '洛宁': 'luoningxian', '茶陵': 'chalingxian', '长丰县': 'changfengxian', '宁陵': 'ninglingxian',
      '南郑区': 'nanzhengxian',
      '酉阳土家族苗族自治县': 'youyangtujiazumiaozuzizh', '秀山土家族苗族自治县': 'xiushantujiazumiaozuzizh', '长清区': 'changqingqu', '嫩江县': 'nenjiangshi', '新津县': 'xinjinqu',
      '靖西市': 'jingxixian',
      '澄江县': 'chengjiangshi', '丰都': 'fengdu', '彭水苗族土家族自治县': 'pengshuizizhixian', '大厂回族自治县': 'dachangzizhixian', '大悟县': 'dawuxia', '景谷': 'jingguxian',
      '富民': 'fuminxian',
      '禄劝彝族苗族自治县': 'luquanxian', '石林彝族自治县': 'shilinxian'}
print(len(sd))